package cn.gson.crm.control.student;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.control.base.BaseServlet;
import cn.gson.crm.model.dao.AllotDao;
import cn.gson.crm.model.dao.StudentDao;
import cn.gson.crm.model.po.StaffPo;
@WebServlet("/student/allot")
public class StudentAllotServlet extends BaseServlet{
	private AllotDao allotDao = new AllotDao();
	private StudentDao studentDao = new StudentDao();
	private String[] ids;
	private String ifallot = null;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
//	@Override
//	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
//		ids = request.getParameterValues("id");
//		ifallot = request.getParameter("ifallot");
//		request.getSession().setAttribute("ifallot", ifallot);
//		request.getSession().setAttribute("ids", ids);
//		List<StaffPo> data = allotDao.getStaffList();
//		if(data != null){
//			request.setAttribute("StaffList", data);
//		}
//		forward("student/student_allot.jsp");
//	}
	@Override
	protected void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String ids =  request.getParameter("ids");
		String [] idss = ids.split(",");
		ifallot = (String) request.getParameter("ifallot");
		String staffid = (String) request.getParameter("staffid");
		System.out.println(ifallot);
		System.out.println(staffid);
		for (String id : idss) {
			if("0".equals(ifallot)||ifallot == null){
				allotDao.insertAllot(id,  staffid);
			}
			else{
				allotDao.updateAllot(staffid, id);
			}
			studentDao.allotStaff(id,staffid);
		}
		
		response.sendRedirect(request.getContextPath() + "/allot/manager");
	}

}
